package com.simtop.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.simtop.domain.Log;
import com.simtop.utils.FileUploadAndDownload;
import com.simtop.utils.ResultBean;
import com.simtop.utils.excel.ExcelUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * @author 文件上传下载
 */
@RestController
@RequestMapping("/common")
public class CommonController {

    private Logger log = LoggerFactory.getLogger(CommonController.class);

    @Autowired
    private FileUploadAndDownload fileUploadAndDownload;

    @Value("${file.profile}")
    private String filePath;

    /**
     * 文件上传
     * @param files
     * @return
     */
    @PostMapping("/upload")
    public ResultBean upload(MultipartFile[] files, HttpServletRequest request){
        String[] arr = new String[files.length];
        for (int i = 0; i < files.length; i++) {
            String richText = fileUploadAndDownload.upload2(files[i], "richText");
            arr[i] = richText;
        }
        return ResultBean.success(arr);
    }

    /**
     * 删除文件
     * @param data
     * @return
     */
    @PostMapping("/delete")
    public ResultBean upload(@RequestBody String data){
        JSONObject jsonObject = JSONObject.parseObject(data);
        JSONArray path = jsonObject.getJSONArray("path");
        try{
            for (Object o : path) {
                File file = new File(filePath + String.valueOf(o));
                file.delete();
            }
            log.info("删除项目文件成功");
            return ResultBean.success("删除成功");
        }catch (Exception e){
            log.info("删除项目文件失败");
            return ResultBean.error("删除失败");
        }
    }

    @GetMapping("/log")

    public void getLog(HttpServletRequest request, HttpServletResponse response) throws ParseException {

        ArrayList<Log> logs = new ArrayList<>(4000);

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < 91; i++) {

            Date date=randomDate("2019-09-01","2020-01-15");

            String format = sdf.format(date);

            Log log = new Log("ZJSD"+getNum(i),null,null,"浙江师范大学","跨境电商保税进口虚拟仿真实验",format,getDate(format),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 452; i++) {

            Date date1=randomDate("2020-02-27","2020-07-01");

            String format1 = sdf.format(date1);

            Log log = new Log("ZJSD"+getNum(i+91),null,null,"浙江师范大学","跨境电商保税进口虚拟仿真实验",format1,getDate(format1),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 2367; i++) {

            Date date2=randomDate("2020-09-01","2021-01-15");

            String format2 = sdf.format(date2);

            Log log = new Log("ZJSD"+getNum(i+543),null,null,"浙江师范大学","跨境电商保税进口虚拟仿真实验",format2,getDate(format2),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 2786; i++) {

            Date date3=randomDate("2021-02-26","2021-05-31");

            String format3 = sdf.format(date3);

            Log log = new Log("ZJSD"+getNum(i+2910),null,null,"浙江师范大学","跨境电商保税进口虚拟仿真实验",format3,getDate(format3),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        new ExcelUtils().cooperationData(request,response,logs,"跨境电商保税进口虚拟仿真实验",Log.class);

    }



    @GetMapping("/log1")

    public void getLog1(HttpServletRequest request, HttpServletResponse response) throws ParseException {

        ArrayList<Log> logs = new ArrayList<>(4000);

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < 313; i++) {

            Date date=randomDate("2019-03-25","2019-06-16");

            String format = sdf.format(date);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format,getDate(format),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 262; i++) {

            Date date1=randomDate("2019-06-17","2019-07-14");

            String format1 = sdf.format(date1);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format1,getDate(format1),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 535; i++) {

            Date date2=randomDate("2019-09-01","2019-11-24");

            String format2 = sdf.format(date2);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format2,getDate(format2),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 1352; i++) {

            Date date3=randomDate("2019-11-25","2020-03-22");

            String format3 = sdf.format(date3);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format3,getDate(format3),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 811; i++) {

            Date date4=randomDate("2020-03-23","2020-06-14");

            String format4 = sdf.format(date4);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format4,getDate(format4),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 242; i++) {

            Date date5=randomDate("2020-06-15","2020-07-12");

            String format5 = sdf.format(date5);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format5,getDate(format5),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 513; i++) {

            Date date6=randomDate("2020-09-07","2020-11-29");

            String format6 = sdf.format(date6);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format6,getDate(format6),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 1198; i++) {

            Date date7=randomDate("2020-11-30","2021-03-28");

            String format7 = sdf.format(date7);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format7,getDate(format7),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 1979; i++) {

            Date date8=randomDate("2021-03-29","2021-06-20");

            String format8 = sdf.format(date8);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海大学","光弹性虚拟仿真实验",format8,getDate(format8),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        new ExcelUtils().cooperationData(request,response,logs,"光弹性虚拟仿真实验",Log.class);

    }



    @GetMapping("/log2")

    public void getLog2(HttpServletRequest request, HttpServletResponse response) throws ParseException {

        ArrayList<Log> logs = new ArrayList<>(8000);

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < 113; i++) {

            Date date=randomDate("2019-03-25","2019-06-16");

            String format = sdf.format(date);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format,getDate(format),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 162; i++) {

            Date date1=randomDate("2019-06-17","2019-07-14");

            String format1 = sdf.format(date1);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format1,getDate(format1),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 235; i++) {

            Date date2=randomDate("2019-09-01","2019-11-24");

            String format2 = sdf.format(date2);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format2,getDate(format2),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 852; i++) {

            Date date3=randomDate("2019-11-25","2020-03-22");

            String format3 = sdf.format(date3);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format3,getDate(format3),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 411; i++) {

            Date date4=randomDate("2020-03-23","2020-06-14");

            String format4 = sdf.format(date4);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format4,getDate(format4),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 142; i++) {

            Date date5=randomDate("2020-06-15","2020-07-12");

            String format5 = sdf.format(date5);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format5,getDate(format5),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 153; i++) {

            Date date6=randomDate("2020-09-07","2020-11-29");

            String format6 = sdf.format(date6);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format6,getDate(format6),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 898; i++) {

            Date date7=randomDate("2020-11-30","2021-03-28");

            String format7 = sdf.format(date7);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format7,getDate(format7),String.valueOf(new Random().nextInt(40)+60));

            logs.add(log);

        }

        for (int i = 0; i < 382; i++) {

            Date date8=randomDate("2021-03-29","2021-06-20");

            String format8 = sdf.format(date8);

            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","大型钢结构多机器人协同焊接控制虚拟仿真实验",format8,getDate(format8),String.valueOf(new Random().nextInt(40)+60));
            logs.add(log);
        }
        new ExcelUtils().cooperationData(request,response,logs,"大型钢结构多机器人协同焊接控制虚拟仿真实验",Log.class);
    }


    @GetMapping("/log3")
    public void getLog3(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        ArrayList<Log> logs = new ArrayList<>(8000);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < 200; i++) {
            Date date=randomDate("2021-06-01","2021-06-15");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"浙江师范大学","中国古代纪年历法虚拟仿真实验",format,getDate(format),getMessage());
            logs.add(log);

        }
        new ExcelUtils().cooperationData(request,response,logs,"浙江师范大学",Log.class);
    }


    @GetMapping("/log4")
    public void getLog4(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        ArrayList<Log> logs = new ArrayList<>(400);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < 200; i++) {
            Date date=randomDate("2021-05-01","2021-07-31");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"华东理工大学","超高压聚乙烯反应釜隐患部位安全评价虚拟仿真实验",format,getDate(format),getMessage2());
            logs.add(log);
        }
        for (int i = 0; i < 200; i++) {
            Date date=randomDate("2021-09-01","2021-10-14");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"华东理工大学","超高压聚乙烯反应釜隐患部位安全评价虚拟仿真实验",format,getDate(format),getMessage2());
            logs.add(log);
        }
        new ExcelUtils().cooperationData(request,response,logs,"华东理工大学",Log.class);
    }


    @GetMapping("/log5")
    public void getLog5(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        ArrayList<Log> logs = new ArrayList<>(400);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < 130; i++) {
            Date date=randomDate("2020-05-01","2020-06-30");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海工程技术大学","驱动电机多物理场特性虚拟仿真实验",format,getDate(format),getMessage3());
            logs.add(log);
        }
        for (int i = 0; i < 126; i++) {
            Date date=randomDate("2020-09-01","2020-11-01");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海工程技术大学","驱动电机多物理场特性虚拟仿真实验",format,getDate(format),getMessage3());
            logs.add(log);
        }
        for (int i = 0; i < 113; i++) {
            Date date=randomDate("2021-05-01","2021-06-30");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海工程技术大学","驱动电机多物理场特性虚拟仿真实验",format,getDate(format),getMessage3());
            logs.add(log);
    }
        new ExcelUtils().cooperationData(request,response,logs,"上海工程技术大学",Log.class);
    }

    @GetMapping("/log6")
    public void getLog6(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        ArrayList<Log> logs = new ArrayList<>(400);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < 152; i++) {
            Date date=randomDate("2020-05-11","2020-05-22");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"","现代计算机CPU体系结构VR虚拟仿真实验软件",format,getDate(format),getMessage4());
            logs.add(log);
        }
        new ExcelUtils().cooperationData(request,response,logs,"x86",Log.class);
    }

    @GetMapping("/log7")
    public void getLog7(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        ArrayList<Log> logs = new ArrayList<>(400);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < 120; i++) {
            Date date=randomDate("2020-09-01","2021-06-30");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海应用技术大学","蚯蚓资源化处理湿垃圾虚拟仿真实验",format,getDate(format),getMessage5());
            logs.add(log);
        }
        for (int i = 0; i < 12; i++) {
            Date date=randomDate("2021-09-01","2021-10-21");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海应用技术大学","蚯蚓资源化处理湿垃圾虚拟仿真实验",format,getDate(format),getMessage5());
            logs.add(log);
        }
        new ExcelUtils().cooperationData(request,response,logs,"蚯蚓资源化处理湿垃圾虚拟仿真实验",Log.class);
    }


    @GetMapping("/log8")
    public void getlog8(HttpServletRequest request, HttpServletResponse response) throws ParseException {
        ArrayList<Log> logs = new ArrayList<>(400);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < 194; i++) {
            Date date=randomDate("2022-09-01","2022-11-30");
            String format = sdf.format(date);
            Log log = new Log(UUID.randomUUID().toString(),null,null,"上海应用技术大学","蚯蚓资源化处理湿垃圾虚拟仿真实验",format,getDate(format),String.valueOf(new Random().nextInt(40)+60));
            logs.add(log);
        }
        new ExcelUtils().cooperationData(request,response,logs,"蚯蚓资源化处理湿垃圾虚拟仿真实验",Log.class);
    }


    public String getMessage(){
        JSONObject jsonObject = new JSONObject();
        int a = new Random().nextInt(30)+20;
        int b = new Random().nextInt(30)+20;
        jsonObject.put("天文观测",a);
        jsonObject.put("综合应用",b);
        jsonObject.put("总分",a+b);
        return jsonObject.toJSONString();
    }

    public String getMessage2(){
        JSONObject jsonObject = new JSONObject();
        int a = new Random().nextInt(4)+6;
        int b = new Random().nextInt(4)+6;
        int c = new Random().nextInt(4)+6;
        int d = new Random().nextInt(2)+3;
        int e = new Random().nextInt(2)+3;
        int f = new Random().nextInt(2)+3;
        int g = new Random().nextInt(4)+6;
        int h = new Random().nextInt(2)+3;
        int i = new Random().nextInt(4)+6;
        int j = new Random().nextInt(4)+6;
        int k = new Random().nextInt(4)+6;
        int l = new Random().nextInt(4)+6;
        jsonObject.put("弹性交互作用模块-设备认知与连接",a);
        jsonObject.put("弹性交互作用模块-顺序拧紧流程",b);
        jsonObject.put("弹性交互作用模块-星型拧紧流程",c);
        jsonObject.put("弹性交互作用模块-拧紧方式分析",d);
        jsonObject.put("螺栓力的超声波检测模块-设备连接",e);
        jsonObject.put("螺栓力的超声波检测模块-设备调节",f);
        jsonObject.put("螺栓力的超声波检测模块-螺栓应力检测",g);
        jsonObject.put("螺栓力的光纤监测模块-材料及设备认知",h);
        jsonObject.put("螺栓力的光纤监测模块-光纤智能螺栓的制作和熔接",i);
        jsonObject.put("螺栓力的光纤监测模块-智能螺栓的标定",j);
        jsonObject.put("螺栓力的光纤监测模块-智能螺栓的监测",k);
        jsonObject.put("实验习题",l);
        jsonObject.put("总分",a+b+c+d+e+f+g+h+i+j+k+l);
        return jsonObject.toJSONString();
    }

    public String getMessage3(){
        StringBuilder sb = new StringBuilder();
        sb.append("{\n" +
                "  \"驱动电机及其物理场概念的认知\": {\n" +
                "    \"驱动电机类型及结构\":"+(new Random().nextInt(11)+18)+",\n" +
                "    \"驱动电机的运转原理\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"不同电机电磁场分析\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"不同电机温度场分析\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"知识考核\":"+(new Random().nextInt(2)+3)+"\n" +
                "  },\n" +
                "  \"驱动电机受外部条件的敏感性分析\": {\n" +
                "    \"电驱条件\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"环境温度\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"冷却输入\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"知识考核\":"+(new Random().nextInt(2)+1)+"\n" +
                "  },\n" +
                "  \"驱动电机机构条件对物理场的分析\": {\n" +
                "    \"转子结构\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"铁芯材料\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"定子结构\":"+(new Random().nextInt(2)+3)+",\n" +
                "    \"知识考核\":"+(new Random().nextInt(1)+2)+",\n" +
                "    \"在线实验\":"+(new Random().nextInt(7)+9)+"\n" +
                "  }\n" +
                "}");
        return sb.toString();
    }


    public String getMessage4(){
        StringBuilder sb = new StringBuilder();
        int i = new Random().nextInt(3) + 5;
        int i1 = 2;
        int i2 = new Random().nextInt(4) + 6;
        int i3 = new Random().nextInt(4) + 6;
        int i4 = new Random().nextInt(4) + 6;
        int i5 = new Random().nextInt(4) + 6;
        int i6 = new Random().nextInt(4) + 6;
        int i7 = new Random().nextInt(4) + 6;
        int i8 = new Random().nextInt(4) + 6;
        int i9 = new Random().nextInt(4) + 6;
        int i10 = new Random().nextInt(4) + 6;

        int total = i+i1+i2+i3+i4+i5+i6+i7+i8+i9+i10;
        sb.append("{\n" +
                "  \"理论知识\": {\n" +
                "    \"X86CPU机械结构\":"+i+",\n" +
                "    \"光量子计算机认知\":"+i1+"\n" +
                "  },\n" +
                "  \"实验预备\": {\n" +
                "    \"主机结构\":"+i2+",\n" +
                "    \"芯片结构\":"+i3+",\n" +
                "    \"知识考核\":"+i4+"\n" +
                "  },\n" +
                "  \"实验操作\": {\n" +
                "    \"硬件设计\":"+i5+",\n" +
                "    \"接口连接\":"+i6+",\n" +
                "    \"编码验证\":"+i7+",\n" +
                "    \"知识考核\":"+i8+",\n" +
                "    \"光量子计算机体系架构\":"+i9+",\n" +
                "    \"光量子计算机光子微观轨迹\":"+i10+"\n" +
                "  },\n" +
                "  \"总分\": "+total+"\n" +
                "}");
        return sb.toString();
    }

    public String getMessage5(){
        StringBuilder sb = new StringBuilder();
        int i = new Random().nextInt(4) + 6;
        int i2 = new Random().nextInt(4) + 6;
        int i3 = new Random().nextInt(4) + 6;
        int i4 = new Random().nextInt(4) + 6;
        int i5 = new Random().nextInt(4) + 6;
        int i6 = new Random().nextInt(4) + 6;
        int i7 = new Random().nextInt(4) + 6;
        int i8 = new Random().nextInt(4) + 6;
        int i9 = new Random().nextInt(4) + 6;
        int i10 = new Random().nextInt(4) + 6;
        int total = i+i2+i3+i4+i5+i6+i7+i8+i9+i10;
        sb.append("{\n" +
                "  \"实验简介\":"+i+",\n" +
                "  \"实验预习：设备认知\":"+i2+",\n" +
                "  \"实验预习：工艺流程\":"+i3+",\n" +
                "  \"实验预习：实验流程模拟\":"+i4+",\n" +
                "  \"在线实验：垃圾分类\":"+i5+",\n" +
                "  \"在线实验：去油装置\":"+i6+",\n" +
                "  \"在线实验：去水装置\":"+i7+",\n" +
                "  \"在线实验：饵料搅拌\":"+i8+",\n" +
                "  \"在线实验：蚯蚓培育装置\":"+i9+",\n" +
                "  \"知识考核\":"+i10+",\n" +
                "  \"总分\":"+total+"\n" +
                "}");
        return sb.toString();
    }
    private static String getNum(int i){
        if(String.valueOf(i).length() == 1){
            return "00000"+i;
        }else if(String.valueOf(i).length() == 2){
            return "0000"+i;
        } else if(String.valueOf(i).length() == 3){
            return "000"+i;
        }else if(String.valueOf(i).length() == 4){
            return "00"+i;
        }else if(String.valueOf(i).length() == 5){
            return "0"+i;
        }else{
            return "000000";
        }
    }



    private static String getDate(String beginTime) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = sdf.parse(beginTime);
        Long design = (new Random().nextInt(20)+15) * 60L * 1000L;
        Long timestamp = parse.getTime() + design;
        String pattern = "yyyy-MM-dd HH:mm:ss";
        return convertTimestamp2Date(timestamp, pattern);
    }



    public static String convertTimestamp2Date(Long timestamp, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date(timestamp));
    }



    /**
     * 获取随机时间
     * @param beginDate
     * @param endDate
     * @return
     */
    private static Date randomDate(String beginDate, String endDate){
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date start = format.parse(beginDate);
            Date end = format.parse(endDate);
            if(start.getTime() >= end.getTime()){
                return null;
            }
            long date = random(start.getTime(),end.getTime());
            return new Date(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    private static long random(long begin,long end){
        long rtn = begin + (long)(Math.random() * (end - begin));
        if(rtn == begin || rtn == end){
            return random(begin,end);
        }
        //判断时间是否在6点到晚上10点内
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(rtn);
        String format = sdf.format(date);
        Integer integer = Integer.valueOf(format.substring(11, 13));
        System.out.println(integer);
        if(integer<9 || integer>20){
            return random(begin,end);
        }
        return rtn;
    }
}
